<include file="header" />
<body>
<div class="wraper">
    <div class="header flex-between">
        <a href="/base/center/center/account_id/{BEESCRM:$account_id}" class="iconfont icon-zuo"></a>
        <div class="title text-center font-16">付款码</div>
        <a href="/base/StoredValue/personalCenter/stored_value_id/{BEESCRM:$stored_value_id}" class="iconfont icon-user font-20"></a>
    </div>
    <div class="box">
        <div class="Barcode center">
            <img src="{BEESCRM::U('base/StoredValue/barcode',array('stored_value_id'=>$stored_value_id,'code_number'=>$code_number))}" alt="">
        </div>
        <div class="erweima center" style="margin: 20px auto 10px">
            <img src="{BEESCRM::U('base/StoredValue/qrcode',array('stored_value_id'=>$stored_value_id,'code_number'=>$code_number))}" alt="">
        </div>
        <p class="text-center">每分钟自动更新</p>
        <div class="logo2 center">
            <img src="/assets/base/StoredValue/images/logo2.png" alt="">
        </div>
    </div>
    <input type="hidden" value="{BEESCRM:$stored_value_id}" id="stored_value_id" />
</div>
</body>
<include file="loadding" />

<include file="commonJs" />
<script type="text/javascript">
    $(function () {
        var time = 60;
        var is_pay = 0;
        var order_id;
        var stored_value_id = $("#stored_value_id").val();
        code_reload(time);
        function code_reload(time) {
            if(is_pay == 0) {
                setTimeout(function () {
                    time--;
                    if (time > 0 && time < 60) {
                        if (time % 3 == 0) {
                            //每隔3秒查询订单是否支付成功
                            select_order();
                        }
                    } else if (time <= 0) { //每分钟刷新一次页面
                        location.href = "/base/StoredValue/payment/stored_value_id/"+stored_value_id;
                    }
                    code_reload(time);
                }, 1000);
            }
        }
        function select_order() {
            $.ajax({
                url: "{BEESCRM::U('/base/StoredValue/doSelectOrderPay',array('stored_value_id'=>$stored_value_id))}",
                type:'POST',
                dataType:'json',
                data:{order_id:order_id},
                success:function (res) {
                    if(res.status == 'S'){
                        is_pay = 1;
                        //支付成功，跳转
                        location.href = "/base/StoredValue/paymentSuccess/stored_value_id/"+ stored_value_id + "/order_id/" + res.order_id;
                    } else if(res.status == 'PS'){
                        order_id = res.order_id;
                    }
                }
            });
        }
    })
</script>